package com.hiultra.archive.device.shelve;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;

/**
 *  连接密集架
 */

public class ShelvesSocketClient extends WebSocketClient {

    //推荐创建不可变静态类成员变量
    private static final Log log = LogFactory.get();
    private SocketMessageListener socketMessageListener;

    public ShelvesSocketClient(URI serverUri) {
        super(serverUri);
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        log.info("-SocketServer");
    }

    @Override
    public void onMessage(String message) {
//        log.info("连接到密集架-SocketServer-收到数据："+message);
        if(socketMessageListener!=null){
            socketMessageListener.onMessage(message);
        }
    }

    @Override
    public void onClose(int i, String s, boolean b) {
        log.info("关闭连接到密集架-SocketServer"+s);
    }

    @Override
    public void onError(Exception e) {
        log.error("连接到密集架-SocketServer-错误："+e.getMessage());
    }

    public void setSocketMessageListener(SocketMessageListener socketMessageListener) {
        this.socketMessageListener = socketMessageListener;
    }
}
